﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;

namespace MDCAdminTool.Commands
{
    class StartPowerShell : AsyncCommandBindingBase
    {
        public StartPowerShell()
            : base()
        {
            Command = Application.Current.Resources["StartPowerShell"] as ICommand;
        }

        protected override void OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var service = e.Parameter as ICacheCommand;
            if(service == null)
            {
                return;
            }

            String host = service.Name;

            String command = "-NoExit -Command \"&{ $s = New-PSSession -ComputerName " + host + "; Invoke-Command { Import-Module DistributedCacheAdministration; Use-CacheCluster } -Session $s; Enter-PSSession $s }\"";
            System.Diagnostics.Process.Start("powershell.exe", command);
        }
    }
}
